#include<iostream>
#include<algorithm>
#include<stdio.h>
using namespace std;
struct hotel
{
    int D;
    int C;
};
bool cmpFun(hotel a,hotel b);
hotel hs[10000];
int main()
{
    int n;
    while(cin>>n,n)
    {
        for(int i = 0 ; i  < n ; i ++)
            scanf("%d %d",&hs[i].D,&hs[i].C);
        sort(hs,hs + n,cmpFun);
        int count = 0,minPrice = 10001;
        for(int i = 0 ; i < n ; i ++)
            if(hs[i].C < minPrice)
                minPrice = hs[i].C , count ++;
        cout<<count<<endl;
    }
    return 0;
}
bool cmpFun(hotel a,hotel b)
{
    if(a.D < b.D)
        return true;
    else if(a.D == b.D)
        return a.C < b.C;
    else
        return false;
}
